import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
// 今天采用路由懒加载得方式把他引进来
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect:"/all" // 地址栏什么都不输入默认是/ ,当访问/得时候，强制去/movie得页面
   
  },
  {
    path:"/all",
    component:()=>import("../views/all"),
    children:[
      {
          path:"/all",
          name:"movie", // 具名路由
          redirect:"/all/movie"
      },
      {
        path:"/all/movie",
        component:()=>import("../views/movie")
    },
    {
      path: '/all/video',
      name: 'video',
      component: () => import( '../views/video.vue')
    },
    {
      path: '/all/shortvideo',
      name: 'shortvideo',
      component: () => import( '../views/shortvideo.vue')
    },
    {
      path:"/all/show",
      name:"show",
      component:()=>import("../views/show")
    },
    ]
  },
  
  {
    path:"/my",
    name:"my",
    component:()=>import("../views/my"),
    beforeEnter(to,from,next){  // 在进入my这个路由之前执行
        console.log(to,"to"); // to是去哪个页面 ，my
        console.log(from,"from") // from 是从哪个页面来 
         if (window.localStorage.getItem("islogin") == "true") {
              next()
         }  else {
             next("/login")
         }
    }
  },
  {
    path:"/detail/:id",
    component:()=>import("../views/detail")
  },
  {
    path:"/login",
    name:"login",
    component:()=>import("../views/login")
  }
  // 导航守卫，守卫路由跳转

]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
